<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<title>俄罗斯转盘游戏模拟</title>
<style>
  body {
    font-family: 'Arial', sans-serif;
    text-align: center;
    margin-top: 50px;
    background-color: #f7f7f7;
  }

  h1 {
    color: #333;
    font-size: 2em;
  }

  p {
    color: #666;
    font-size: 1em;
  }

  #trigger {
    padding: 10px 20px;
    font-size: 1em;
    cursor: pointer;
    background-color: #fff;
    border: 1px solid #ddd;
    border-radius: 4px;
  }

  #trigger:hover {
    background-color: #f0f0f0;
  }
</style>
<script>
// 生成子弹的总数量和实弹的数量
function loadChamber() {
  var totalBullets = Math.floor(Math.random() * 7) + 3; // 3-9颗子弹
  var liveBullets = Math.floor(Math.random() * (totalBullets / 2)) + 1; // 实弹至少一颗，且不大于虚弹数量
  var emptyBullets = totalBullets - liveBullets; // 虚弹的数量

  // 更新页面上的信息
  document.getElementById('totalBullets').textContent = totalBullets;
  document.getElementById('liveBullets').textContent = liveBullets;
  document.getElementById('emptyBullets').textContent = emptyBullets;
}

// 触发“开枪”或“安全”的事件
function pullTrigger() {
  var liveBulletsElement = document.getElementById('liveBullets');
  var liveBullets = parseInt(liveBulletsElement.textContent, 10);
  var emptyBulletsElement = document.getElementById('emptyBullets');
  var emptyBullets = parseInt(emptyBulletsElement.textContent, 10);
  var totalBulletsElement = document.getElementById('totalBullets');
  var totalBullets = parseInt(totalBulletsElement.textContent, 10);

  if (totalBullets > 0) {
    var result = Math.random() < (liveBullets / totalBullets) ? '开枪！' : '安全！';
    alert(result);

    // 根据结果减少实弹或虚弹的数量
    if (result === '开枪！') {
      liveBullets--;
      liveBulletsElement.textContent = liveBullets;
    } else {
      emptyBullets--;
      emptyBulletsElement.textContent = emptyBullets;
    }

    // 减少总子弹数量
    totalBullets--;
    totalBulletsElement.textContent = totalBullets;

    // 如果总子弹为零，刷新界面
    if (totalBullets === 0) {
      loadChamber();
    }
  }
}

// 在页面加载时初始化游戏
window.onload = function() {
  loadChamber();
  document.getElementById('trigger').onclick = pullTrigger;
};
</script>
</head>
<body>
<h1>俄罗斯转盘游戏模拟</h1>
<div>
  <p>子弹的总数量：<span id="totalBullets">?</span>颗</p>
  <p>实弹的数量：<span id="liveBullets">?</span>颗</p>
  <p>虚弹的数量：<span id="emptyBullets">?</span>颗</p>
  <button id="trigger">拉动扳机</button>
</div>
</body>
</html>
